//
//  StatusCellBottomCell.swift
//  xinlangweibo
//
//  Created by yangshuo on 15/12/4.
//  Copyright © 2015年 yangshuo. All rights reserved.
//

import UIKit

class StatusCellBottomView: UIView {
    //指定构造函数,来加载界面
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    //底部视图的button可以使用便利构造函数抽取条件
    //懒加载button
    ///转发按钮
    private lazy var retweetedButton: UIButton = UIButton(title: "转发", color: UIColor.darkGrayColor(), fontSize: 12, imageName: "timeline_icon_retweet")
    ///评论按钮
    private lazy var commenButton: UIButton = UIButton(title: "评论", color: UIColor.darkGrayColor(), fontSize: 12, imageName: "timeline_icon_comment")
    //点赞按钮
    private lazy var likeButton: UIButton = UIButton(title: "点赞", color: UIColor.darkGrayColor(), fontSize: 12, imageName: "timeline_icon_unlike")
}
//MARK: - 设置界面
extension StatusCellBottomView{
    private func setupUI(){
        backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        
        //添加控件
        addSubview(retweetedButton)
        addSubview(commenButton)
        addSubview(likeButton)
        
        
        //自动布局
        //设置三个按钮的宽度的关键,最左边的按钮与底部视图左对齐,最右边的按钮与底部视图右对齐,在设置三个按钮等宽即可
        
        //转发按钮
        retweetedButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            //设置按钮宽度的关键
            make.left.equalTo(self.snp_left)

        }
        //评论按钮
        commenButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedButton.snp_top)
            make.left.equalTo(retweetedButton.snp_right)
            make.bottom.equalTo(retweetedButton.snp_bottom)
            make.width.equalTo(retweetedButton.snp_width)
        }
        //点赞按钮
        likeButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(commenButton.snp_top)
            make.left.equalTo(commenButton.snp_right)
            make.bottom.equalTo(commenButton.snp_bottom)
            make.width.equalTo(retweetedButton.snp_width)
            //设置按钮宽度的关键
   make.right.equalTo(self.snp_right)
        }
        
        //分割线宽,高
        //如果不加CGFloat的w就表示的点,加上CGFloat表示的是像素?
        let w: CGFloat = 1
        let scale: CGFloat = 0.4
        //设置分割线
        let sepView1 = sepView()
        let sepView2 = sepView()
        
        //在显示控件之前不要忘了addsubview!!
        addSubview(sepView1)
        addSubview(sepView2)

        //分割线自动布局
        sepView1.snp_makeConstraints { (make) -> Void in
        make.left.equalTo(retweetedButton.snp_right)//等同于设置sepView的X
       // 注意不能通过设置centerY来试图设置控件的高度!!
            make.centerY.equalTo(retweetedButton.snp_centerY)
            make.width.equalTo(w)
        make.height.equalTo(retweetedButton.snp_height).multipliedBy(scale)
        }
        sepView2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commenButton.snp_right)
        make.centerY.equalTo(commenButton.snp_centerY)
            make.width.equalTo(w)
        make.height.equalTo(commenButton.snp_height).multipliedBy(scale)
        }
    }
    //分割线函数(使用view,因为view最轻量级)
    func sepView() -> UIView{
        //实例化
        let v = UIView()
        v.backgroundColor = UIColor.darkGrayColor()
        return v
    }
}
